package com.goldstone.entity;


import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import com.goldstone.entity.code.PriceType;

@Embeddable
public class PriceLog {
	private Float price;
	private Company supplier;
	private Company customer;
	private PriceType priceType;
	private String descs;
	private Date timestamp = new Date();
	private String compId;
	
	public PriceLog() { }
	
	public PriceLog(Float price) {
		this.price = price;
	}
	
	public PriceLog(Float price, Company comp, PriceType type) {
		this.price = price;
		this.priceType = type;
		if(type.equals(PriceType.CP)) {
			this.customer = comp;
		} else {
			this.supplier = comp;
		}
	}
	
	@Column(nullable = true)
	public Float getPrice() {
		return price;
	}
	public void setPrice(Float price) {
		this.price = price;
	}
	
	@ManyToOne
	@JoinColumn(name = "SUPPLIER_ID", insertable = false, updatable = false)
	public Company getSupplier() {
		return supplier;
	}
	public void setSupplier(Company supplier) {
		this.supplier = supplier;
	}
	
	@ManyToOne
	@JoinColumn(name = "CUSTOMER_ID", insertable = false, updatable = false)
	public Company getCustomer() {
		return customer;
	}
	public void setCustomer(Company customer) {
		this.customer = customer;
	}
	public Date getTimestamp() {
		return timestamp;
	}
	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}

	public PriceType getPriceType() {
		return priceType;
	}

	public void setPriceType(PriceType priceType) {
		this.priceType = priceType;
	}

	public String getDescs() {
		return descs;
	}

	public void setDescs(String descs) {
		this.descs = descs;
	}
	
	@Transient
	public String getCompId() {
		return compId;
	}

	public void setCompId(String compId) {
		this.compId = compId;
	}
	
}
